@extends('layouts.app')

@section('layout_body')
	<div class="container py-5">
	    <div class="row justify-content-center">
	        <div class="col-12">
	        	<div class="alert alert-primary text-center" role="alert">
					请微信扫描下方二维码进行付款，支付过程请勿关闭或刷新页面。
				</div>
{{--				<input type="hidden" class="domain" value="{{env('APP_URL')}}">--}}
				<input type="hidden" class="order_num" value="{{$data['order_num']}}">
				<div class="text-center">
					<img src="https://api.pwmqr.com/qrcode/create/?url={{ $data['qrcode'] }}" class="img-fluid">

					<div>微信扫码 , 支付 <span class="h1">{{$data['money']}}</span>  元</div>
				</div>
	        </div>
	    </div>
	</div>
@endsection

@section('script')
    <script type="text/javascript">
		$.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
		function pay_status(){
		    var order_num = $('.order_num').val();
		    // var domain = $('.domain').val();
		    $.ajax({
			    url:  '/checkWechatPay',
			    type:'post',
			    data:{'order_num':order_num},
			    success:function(data){
			        if(data.code == '1' ){
				        window.clearInterval(int); //销毁定时器
				        setTimeout(function(){
				            //跳转到结果页面，并传递状态
				            alert(data.msg);
				            if (data.result.type == '1') {
						        window.location = '/manager/recharge';
				            } else {
				            	window.location = '/user/moneyLog';
				            }
				        },1000)
			        }
			    },
		    });
		}
		//启动定时器
		var int=self.setInterval(function(){pay_status()},1000);
	</script>
@endsection
